#include "can_task.h"

void can_send(QueueHandle_t* queue, CAN_HandleTypeDef* hcan)
{
    BaseType_t status;
    can_message msg;
    uint32_t mailbox;
    status = xQueueReceive(*queue, &msg, 100);
    UNUSED(status);
    while (HAL_CAN_GetTxMailboxesFreeLevel(hcan) == 0)
    {
        vTaskDelay(1);
    }
    HAL_CAN_AddTxMessage(hcan, &msg.tx_header, msg.data, &mailbox);
}

void StartCan1Task(void *argument)
{
    UNUSED(argument);
    while (1)
    {
        extern QueueHandle_t can1MessageQueueHandle;
        can_send(&can1MessageQueueHandle, &hcan1);
    }
}

void StartCan2Task(void *argument)
{
    UNUSED(argument);
    while (1)
    {
        extern QueueHandle_t can2MessageQueueHandle;
        can_send(&can2MessageQueueHandle, &hcan2);
    }
    
}
